
//定义一个Dog类
public class Dog {
    //成员变量
    public String name;
    public String color;
    //成员方法
    public void barks(){
        System.out.println(name + "汪汪叫！");
    }
    public void wag(){
        System.out.println(name + "摇尾巴");
    }
    //main方法
    public static void main(String[] args) {
        //实例化一个Dog对象
        Dog dog = new Dog();
        //点号(.)-》调用的意思
        //1.可以通过 引用.属性来访问属性
        dog.name = "小灰";
        dog.color = "灰色";
        System.out.println(dog.name);
        System.out.println(dog.color);
        //2.可以通过 引用.方法来访问方法
        dog.barks();
        dog.wag();
        //实例化一个dog2对象
        Dog dog2 = new Dog();
        dog2.name = "大黄";
        dog2.color = "黄色";
        System.out.println(dog2.name);
        System.out.println(dog2.color);
        dog2.barks();
        dog2.wag();
    }
}
